<#assign filePath>${project.projectName}/${project.projectName}-biz/src/main/resources/db/migration/</#assign>
<#assign fileName>V1.0.0_${module.moduleCode}__${module.moduleName?replace(".","_")}_init.sql</#assign>
<#list module.modelList as model>
  <#if model.tableName?has_content >
CREATE TABLE `${model.tableName}`
(
    <#list model.fieldList as field>
      <#assign dbType = db_type(field)!''>
      <#if dbType!='' && !(["deleted","create_time","update_time"]?seq_contains(field.name))>
        <#if model.primaryFieldId?? && model.primaryFieldId == field.id >
    `${db_field(field.name)}` ${dbType} UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '${field.remark}',
        <#else>
    `${db_field(field.name)}` ${dbType} <#if field.required>NOT NULL<#else>NULL</#if> COMMENT '${field.remark}',
        </#if>
      </#if>
    </#list>
    `deleted`     BIT         NOT NULL DEFAULT 0 COMMENT '是否删除',
    `create_time` DATETIME(3)      NOT NULL COMMENT '创建时间',
    `update_time` DATETIME(3)      NOT NULL COMMENT '更新时间',
    <#list model.fieldList as field>
      <#if model.primaryFieldId?? && model.primaryFieldId == field.id >
    PRIMARY KEY (`${field.name}` DESC)
      </#if>
    </#list>
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4 COMMENT ='${model.remark}'
  AUTO_INCREMENT = 1000;
  </#if>

</#list>